var component = {
    //定义参数
    pageNow:null,        //当前页
    pageTotal:null,      //总页数
    url:location.href,   //页面URL 
    r:location.href.search(/\.html/ig),  //url 正则匹配到 .html
    r1:location.href.search(/_/ig),      //url 正则匹配到 _


    //参数处理
    argumentHandle:function(args) {

        if ((args['pageNow'] || args['pageTotal']) === null)
            return ;

        component.pageNow = args['pageNow'];
        component.pageTotal = args['pageTotal'];

    },

    /*
        url处理
        @param integet hpage 处理页
        问题：没有处理 第0页 和 >pageTotal的情况
    */
    urlHandle:function(hpage) {
        var url_switch = '';
       
        if (component.r > 0) {
            if (component.pageNow == 1) 
                url_switch = component.url.substr(0,component.r);  //http://www.xxx.com/xxx.html
            else 
                url_switch = component.url.substr(0,component.r1); //http://www.xxx.com/xxx_x.html

            if (hpage == 1)
                location.href = url_switch+".html";
            else 
                location.href = url_switch+"_"+hpage+".html#p=" +  hpage;
        }
    }, 

    /*
        左右箭头跳转
        @param int num 1：上一页 2：下一页

    */
    leftRightJump:function(num) {
        if ((component.pageNow === null) && (component.pageTotal === null))
            return;
        
        var jump_page;

        if (num == 1) {
        	jump_page = component.pageNow - 1;
           
        	if (jump_page < 1) {
        		component.prevImgs();
        		return false;
        	}
        	
            component.urlHandle(jump_page);
        } else if (num == 2) {

        	jump_page = component.pageNow + 1;
     
        	if (jump_page > component.pageTotal) {
        		$(".others_like").show();
    			$(".pop_img").hide();
    			return false;
        	}

            component.urlHandle(jump_page);
        }
    },
    
    //上一页图集
    prevImgs:function() {
    	var pre_url = $('.back_album a').attr('href');
    	
    	if (pre_url == null) {
    		alert('亲，上一页图集还没有哦~~~~');
    		return false;
    	}
    	
    	location.href = pre_url;
    },
    
    //图片根据url参数#p=xx 默认选中
    imgSelected:function() {
    	var pos = location.href.indexOf('#');
    	var str,arr,url_page;

    	if (pos != -1) {
    		str = location.href.substr(pos + 1);
			arr = str.split("=");   
			url_page = arr[1];
    	} else {
			url_page = 1;
    	}

    	$('#picList li').eq(url_page-1).children('img').addClass('current');
    },
    
    //滚动条定位
    scrollbarPosition:function() {
    	
    	if (component.r1 > 0) 
    		$(document).scrollTop(225);
    	
    } 


};